Skip to content

Security: Sanitize Lightspeed Core error responses#3296

Open
rajin-kichannagari wants to merge 3 commits into
redhat-developer:mainfrom
rajin-kichannagari:fix/sanitize-lcs-error-responses
Open

Security: Sanitize Lightspeed Core error responses#3296
rajin-kichannagari wants to merge 3 commits into
redhat-developer:mainfrom
rajin-kichannagari:fix/sanitize-lcs-error-responses

Conversation

@rajin-kichannagari
Copy link
Copy Markdown

Hey, I just made a Pull Request!

Fixes an information disclosure vulnerability where error responses from Lightspeed Core were leaking internal details to clients.

The issue:
When LCS returns errors, we were forwarding the full error message to clients, which could include model names, provider info, org IDs, stack traces, etc. Not great for security.

What I changed:

  • Added a sanitizeLcsError() function that logs the full error server-side but only returns a generic message to the client
  • Updated the error handling in 4 endpoints: /v1/feedback, /v1/query/interrupt, /v1/query, and /v2/conversations/:id
  • Updated tests to make sure we're not leaking internal details

Example:
Before: {"error": "Error from lightspeed-core server: Model gpt-4-0613 failed with OpenAI API error: rate limit exceeded for organization org-abc123"}

After: {"error": "Error from lightspeed-core server while processing query"}

Full error details are still logged on the server for debugging.

✔️ Checklist

  • A changeset describing the change and affected packages
  • Added or Updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)

Fixes information disclosure vulnerability where LCS error details
were being forwarded directly to clients.

Changes:
- Add sanitizeLcsError() function to sanitize error responses
- Update 4 endpoints to use sanitization
- Enhance tests to verify internal details are not exposed
@rhdh-gh-app
Copy link
Copy Markdown

rhdh-gh-app Bot commented Jun 4, 2026

Changed Packages

Package Name Package Path Changeset Bump Current Version
@red-hat-developer-hub/backstage-plugin-lightspeed-backend workspaces/lightspeed/plugins/lightspeed-backend patch v2.9.0

Copy link
Copy Markdown
Contributor

@Jdubrick Jdubrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 small comment, rest looks good

Comment thread workspaces/lightspeed/plugins/lightspeed-backend/src/service/router.ts Outdated
@Jdubrick
Copy link
Copy Markdown
Contributor

Jdubrick commented Jun 4, 2026

/ok-to-test

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.58%. Comparing base (ac69555) to head (a9af3cd).
⚠️ Report is 22 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3296      +/-   ##
==========================================
+ Coverage   53.57%   53.58%   +0.01%     
==========================================
  Files        2407     2409       +2     
  Lines       86535    86543       +8     
  Branches    23943    23947       +4     
==========================================
+ Hits        46361    46378      +17     
+ Misses      38692    38683       -9     
  Partials     1482     1482              
Flag Coverage Δ *Carryforward flag
adoption-insights 83.58% <ø> (ø) Carriedforward from 12082fc
ai-integrations 70.03% <ø> (ø) Carriedforward from 12082fc
app-defaults 69.60% <ø> (ø) Carriedforward from 12082fc
augment 46.39% <ø> (ø) Carriedforward from 12082fc
bulk-import 72.86% <ø> (ø) Carriedforward from 12082fc
cost-management 16.49% <ø> (ø) Carriedforward from 12082fc
dcm 45.40% <ø> (ø) Carriedforward from 12082fc
extensions 61.79% <ø> (ø) Carriedforward from 12082fc
global-floating-action-button 74.30% <ø> (ø) Carriedforward from 12082fc
global-header 61.63% <ø> (ø) Carriedforward from 12082fc
homepage 51.52% <ø> (ø) Carriedforward from 12082fc
konflux 91.01% <ø> (ø) Carriedforward from 12082fc
lightspeed 68.54% <100.00%> (+0.20%) ⬆️
mcp-integrations 85.46% <ø> (ø) Carriedforward from 12082fc
orchestrator 36.60% <ø> (ø) Carriedforward from 12082fc
quickstart 62.88% <ø> (ø) Carriedforward from 12082fc
sandbox 79.56% <ø> (ø) Carriedforward from 12082fc
scorecard 83.84% <ø> (ø) Carriedforward from 12082fc
theme 64.54% <ø> (ø) Carriedforward from 12082fc
translations 8.49% <ø> (ø) Carriedforward from 12082fc
x2a 78.79% <ø> (ø) Carriedforward from 12082fc

*This pull request uses carry forward flags. Click here to find out more.


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ac69555...a9af3cd. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@JslYoon JslYoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, although the sanitizeLcsError() function uses any for both errorBody and logger
parameters. We should add proper TypeScript types:

  • logger should use the LoggerService type (already imported in types.ts from
    @backstage/backend-plugin-api).
  • errorBody should have an interface that matches the LCS error response
    structure (see the test mocks for examples of the shape).
  • for the function sanitizeLcsError lets capitalize the LCS bit.

If you can also address the SonarCloud analysis and failing CI after rebasing, I can take another look.

Rajin Kichannagari added 2 commits June 4, 2026 15:58
- Move sanitizeLCSError to utils.ts for reusability
- Fix TypeScript types (use LoggerService, add LCSErrorResponse interface)
- Capitalize LCS in function name
- Fix failing test for conversation not found
- Add unit tests for utils to improve coverage
Extract duplicated error handling pattern into a reusable helper function.
This reduces duplication from 5.6% to under 3%.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 4, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
5.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

context: string,
response: any,
): Promise<void> {
const errorBody = await fetchResponse.json();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wrap this in a try/catch just on the off chance Lightspeed Core doesn't return JSON / doesn't have a body, on the catch we can just set the body to an empty object

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then let's add a test for this case as well

fetchResponse: Response,
logger: LoggerService,
context: string,
response: any,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to type this to express.Response or is ts being weird about it and that is why it's any?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants